home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / MULTIMAP.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  70 lines

  1.  #include <string>
  2.  #include <map>
  3.  
  4.  using namespace std;
  5.  
  6.  typedef multimap<int, string, less<int> > months_type;
  7.  
  8.  //
  9.  // Print out a pair.
  10.  //
  11.  template <class First, class Second>
  12.  ostream& operator<< (ostream& out, const pair<First,Second>& p)
  13.  {
  14.    out << p.second << " has " << p.first << " days";
  15.    return out;
  16.  }
  17.  
  18.  //
  19.  // Print out a multimap.
  20.  //
  21.  ostream& operator<< (ostream& out, months_type l)
  22.  {
  23.    copy(l.begin(),l.end(), ostream_iterator
  24.         <months_type::value_type>(cout,"\n"));
  25.    return out;
  26.  }
  27.  
  28.  int main ()
  29.  {
  30.    //
  31.    // Create a multimap of months and the number of days in the month.
  32.    //
  33.    months_type months;
  34.  
  35.    typedef months_type::value_type value_type;
  36.    //
  37.    // Put the months in the multimap.
  38.    //
  39.    months.insert(value_type(31, string("January")));
  40.    months.insert(value_type(28, string("Febuary")));
  41.    months.insert(value_type(31, string("March")));
  42.    months.insert(value_type(30, string("April")));
  43.    months.insert(value_type(31, string("May")));
  44.    months.insert(value_type(30, string("June")));
  45.    months.insert(value_type(31, string("July")));
  46.    months.insert(value_type(31, string("August")));
  47.    months.insert(value_type(30, string("September")));
  48.    months.insert(value_type(31, string("October")));
  49.    months.insert(value_type(30, string("November")));
  50.    months.insert(value_type(31, string("December")));
  51.    //
  52.    // Print out the months.
  53.    //
  54.    cout << "All months of the year" << endl << months << endl;
  55.    //
  56.    // Find the Months with 30 days.
  57.    //
  58.    pair<months_type::iterator,months_type::iterator> p =
  59.           months.equal_range(30);
  60.    //
  61.    // Print out the 30 day months.
  62.    //
  63.    cout << endl << "Months with 30 days" << endl;
  64.    copy(p.first,p.second,ostream_iterator<months_type::value_type>(cout,"\n"));
  65.  
  66.    return 0;
  67.  }
  68.  
  69.  
  70.